<!doctype html>
<html>
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<meta content="always" name="referrer">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<#include "../common/header.html">
</head>
<body>
<!--最外面的灰底框,用于与ifram区别开-->
<div class="col-xs-12 lightgray_div" >
	<!--白底框-->
	<div class="col-xs-12 white_div">
		<!--搜索框-->
		<div class="col-xs-12 search_div" >
			<div class="input-group g-fr">
				<form id="inquire" class="form-inline ">
					<input type="hidden" id="type_id" name="type_id" value="${type_id!?html}">
					<div class="input-group ">
						<input type="text"  class="form-control" name="search" placeholder="编码名称" >
					</div>
					<button type="button" class="layui-btn" style="height: 30px" id="btn_search" onclick="table_func.search()" ><i class="layui-icon layui-icon-search"></i></button>
				</form>
			</div>
		</div>
		<div class="col-xs-12" style="height: 100%" >
			<table id="table_div" lay-filter="main" ></table>
		</div>
	</div>
</div>
</body>
<#include "../common/layui_init.html">
<!--表格工具类的按钮-->
<script type="text/html" id="toolbarBox">
	<div  style="margin-bottom: -5px">
		<div class="layui-btn-container " style="float: left;">
			<button class="layui-btn " onclick="table_func.add()"><i class="layui-icon layui-icon-add-1"></i>添加</button>
			<button class="layui-btn  layui-btn-normal" onclick="table_func.edit()"><i class="layui-icon layui-icon-edit"></i>编辑</button>
			<button class="layui-btn  layui-btn-danger" onclick="table_func.remove()"> <i class="layui-icon layui-icon-delete"></i>删除</button>
			<button class="layui-btn" onclick="table_func.enabled_code()" ><i class="layui-icon layui-icon-ok"></i>启用</button>
			<button class="layui-btn" onclick="table_func.disabled_code()" ><i class="layui-icon layui-icon-close"></i>禁用</button>
			<button class="layui-btn " onclick="table_func.back()" style="background-color: #C0C0C0;" ><i class="glyphicon glyphicon-arrow-left"></i>返回</button>
			<!--<button class="layui-btn" onclick="table_func.manage()" ><i></i>管理</button>-->
		</div>
	</div>
</script>

<script type="text/javascript">

	//表头
	var cols=[[
		{field: 'id', title: 'id', sort: true,type:'checkbox', fixed: 'left'}
		,{field: 'id', title: 'ID'}
		,{field: 'name', title: '字典值'}
		// ,{field: 'code', title: '字典类型编码'}
		// ,{field: 'type', title: '字典类型'
		// 	,templet:function (col) {
		// 		return "dd";
		// 	}
		// }
		// ,{field: 'parent_code', title: '上级编码'}
		// ,{field: 'creator_id', title: '创建人id'}
		,{field: 'describe_info', title: '描述'}
		,{field: 'sort', title: '序号'}
		,{field: 'status', title: '状态',templet:function (col) {
				if(col.status==0){
					return "正常"
				}else if(col.status==-1){
					return "<span style='color: red'>禁用</span>"
				}else{
					return "未知状态"
				}
			}
		}, {
			field: 'gmt_create', title: '创建时间'
			, templet: function (col) {
				return layui_table.date_format(col.gmt_create, "yyyy-MM-dd hh:mm:ss")
			}
		},
		{
			field: 'gmt_create', title: '修改时间'
			, templet: function (col) {
				return layui_table.date_format(col.gmt_modified, "yyyy-MM-dd hh:mm:ss")
			}
		}
	]]
	//页面要用的方法
	table_func={
		//表格初始化
		init:function(){
			//设置表格渲染的参数
			layui_table.set_table_data_where('${request.contextPath}/dict/query',tool.paraArrayToLiteral($("#inquire").serializeArray()),cols,"#toolbarBox");
			//进行表格渲染
			layui_table.table_render();
		},
		//搜索
		search:function(){
			layui_table.search(tool.paraArrayToLiteral($("#inquire").serializeArray()))
		},
		//添加一个
		add:function () {
			window.location.href="${request.contextPath}/pages/dict/add?type_id=${type_id!?html}";
		},
		//编辑
		edit:function () {
			var ids=layui_table.selectOne();
			if(ids!=null){
				window.location.href="${request.contextPath}/pages/dict/add?id="+ids+"&type_id=${type_id!?html}";
			}
		},
		//删除
		remove:function(){
			var ids=layui_table.selectMany();
			if(ids!=null){
				var op=layer.confirm('确认要删除吗？', {
					btn: ['确定','取消'] //按钮
				}, function(){
					$.post("${request.contextPath}/dict/delete",{ids:ids.toString()},function(o){
						if(o.code==0){
							layer.msg(o.message);
							table_func.search();
						}else{
							layui_layer.error_alert(o.message);
						}
					});
					layer.close(op)
				}, function(){

				});

			}
		},
		//启用
		enabled_code:function(){
			var ids=layui_table.selectMany();
			if(ids!=null){
				$.post("${request.contextPath}/dict/dict_enable",{ids:ids.toString()},function(o){
					if(o.code==0){
						layer.msg(o.message);
						table_func.search();
					}else{
						layui_layer.error_alert(o.message);
					}
				});
			}
		},
		//禁用
		disabled_code:function(){
			var ids=layui_table.selectMany();
			if(ids!=null){
				$.post("${request.contextPath}/dict/dict_disabled",{ids:ids.toString()},function(o){
					if(o.code==0){
						layer.msg(o.message);
						table_func.search();
					}else{
						layui_layer.error_alert(o.message);
					}
				});
			}
		},
		back:function () {
			window.location.href="${request.contextPath}/pages/dict/type_index";
		}
	}
	$(function () {
		//设置表格的属性值
		layui_table.lay_attr=$("#table_div").attr("lay-filter");
		//设置点击表格行,进行选中
		layui_table.click_line_checked();
		table_func.init();
	});
</script>



<#include "../common/footer-inner.html">
</html>
